type callbackId = int

module SignalsMap = Map.Make(struct type t = callbackId let compare x y = compare x y end)

class type ['a] eventItf = object
	method connect: 'a -> callbackId
	method disconnect: callbackId -> unit
end
	
class ['a] event () = object(self)
	val mutable sMap = SignalsMap.empty
	val mutable curId = 0
		
	method connect (callback:'a) =
		curId <- curId + 1;
		sMap <- SignalsMap.add curId callback sMap;
		curId

	method disconnect signalId =
		sMap <- SignalsMap.remove signalId sMap

	method as_event_itf =
		(self :> 'a eventItf)
			
	method emit emitter =
		SignalsMap.iter (fun _ f -> emitter f) sMap
end

let emtr p f = f p

let emtr2 p1 p2 f =
	f p1 p2

let emtr3 p1 p2 p3 f =
	f p1 p2 p3

let emtr4 p1 p2 p3 p4 f =
	f p1 p2 p3 p4

let emtr5 p1 p2 p3 p4 p5 f =
	f p1 p2 p3 p4 p5
